<template>
  <!--登录-->
  <div class="wrap">
    <div class="tdbModule loginPage">
      <div class="registerTitle">用户登录</div>
      <div class="registerCont">
        <ul>
          <!--                    <li>-->
          <!--                        <span class="dis"></span>-->
          <!--                        <input v-model="userInfo.userType" type="radio" value="1"/>-->
          <!--                        投资人-->
          <!--                        <input v-model="userInfo.userType" type="radio" value="2"/>-->
          <!--                        借款人-->
          <!--                    </li>-->
          <li>
            <span class="dis">手机号：</span>
            <input v-model="userInfo.username" class="input"/>
          </li>

          <li>
            <span class="dis">密码：</span>
            <input v-model="userInfo.password" class="input" type="password"/>
          </li>
          <li class="btn">
            <button :class="{ disabled: !isValid }" @click="login()">
              立即登录
            </button>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import '~/assets/css/register.css'
import cookie from 'js-cookie'

export default {
  data() {
    return {
      userInfo: {
        userType: 1,
        username: '',
        password: ''
      },
      isValid: true, //表单校验是否成功
    }
  },

  methods: {
    //登录
    login() {
      let ss = {
        "username": this.userInfo.username,
        "password": this.userInfo.password
      }
      this.$axios.$post('http://localhost:8401/tb-user/userLogin', ss).then((response) => {

        if (response.code == 200) {
          this.$router.push('/user')
          this.$message.success("ok")
          cookie.set('userInfo', response.data)
        } else {
          this.$message.error("error")
        }
      })
    }
  }
}
</script>
